package com.oig.sys.base.dao;

import com.oig.sys.base.entity.TbArea;
import com.oig.sys.base.vo.AreaVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
@author wuxl
*/
public interface ITbAreaDao extends JpaRepository<TbArea, Integer>, JpaSpecificationExecutor<TbArea> {

	TbArea getTbAreaById(Integer id);

	TbArea getByCode(String code);

	TbArea getByName(String name);

	@Query("from TbArea a where a.code in(:codeList)")
	List<TbArea> findAreaByCodeList(@Param("codeList") List<String> codeList);


	@Query("select new com.oig.sys.base.vo.AreaVo(a.id, a.countryCode, a.code, a.name, a.enName, a.status," +
			" a.treePath, a.fullName, a.grade, a.parentId, a.subIndex) " +
			" from TbArea a where a.parentId=:parentId")
	List<AreaVo> findByParentId(@Param("parentId")Integer parentId);

	@Query("select new com.oig.sys.base.vo.AreaVo(a.id, a.countryCode, a.code, a.name, a.enName, a.status," +
			" a.treePath, a.fullName, a.grade, a.parentId, a.subIndex) " +
			" from TbArea a where a.countryCode=:countryCode")
	List<AreaVo> findByCountryCode(@Param("countryCode")String countryCode);
}
